package com.dick.base.api;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dick.base.model.BusinessRoll;
import com.dick.base.model.BusinessRollAll;
import com.dick.base.parameter.RollAddParameter;
import com.dick.base.parameter.RollModifyParameter;
import com.dick.base.service.RollService;
import com.dick.base.util.BaseResult;
import com.dick.base.util.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;

@RestController
@RequestMapping("api/rolls")
public class RollApi {

    private static final String TAG = "材料卷";

    @Autowired
    private RollService rollService;

    @ApiOperation(value = "分页查询", tags = TAG)
    @GetMapping(path = "get")
    public BaseResult<Page<BusinessRollAll>> rollPage(BusinessRollAll roll, PageInfo pageInfo) {
        return BaseResult.of(rollService.rollPage(roll, pageInfo));
    }

    @ApiOperation(value = "新增", tags = TAG)
    @PostMapping
    public BaseResult<Void> rollAdd(@RequestBody @Valid RollAddParameter parameter) {
        rollService.rollAdd(parameter);
        return BaseResult.voidResult();
    }

    @ApiOperation(value = "修改", tags = TAG)
    @PostMapping("modify")
    public BaseResult<Void> rollModify(@RequestBody @Valid RollModifyParameter parameter) {
        rollService.rollModify(parameter);
        return BaseResult.voidResult();
    }
}
